Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txn: fix retry with non autocommit #22875

Merged

Conversation

cfzjywxk
Copy link
Contributor

@cfzjywxk cfzjywxk commented Feb 22, 2021

What problem does this PR solve?

Issue Number: close #22874

Problem Summary:
The txn retry for non autocommit mode does not set flag correctly like mysql.ServerStatusInTrans.

What is changed and how it works?

What's Changed:

  • Try to make transaction activiation use the same logic for common and retrying transactions.
  • Make multiple transaction activiation interfaces use the same inner activiation logic, avoid maintaining duplicate codes.(There is still some refactor work need to do for this part, these transaction interfaces are diffuicult to distinguish and use).
  • There are three different transaction activiation interfaces, NewTxn, txn.Txn(true), initTxnWithStartTS, and they have some their own initilizing logic.
  • Above issues will be recorded as refactor tasks in the future, to lower the changing risk in release branch.
  • Add flag for the multiple statments transaction retry path.

How it Works:

Related changes

Check List

Tests

  • Unit test

Side effects

Release note

  • Fix the issue that transaction retry with non-autocommit mode may write incorrect data.

@cfzjywxk cfzjywxk added type/bugfix This PR fixes a bug. priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/transaction SIG:Transaction labels Feb 22, 2021
@cfzjywxk cfzjywxk added this to the v4.0.11 milestone Feb 22, 2021
@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 22, 2021
@cfzjywxk
Copy link
Contributor Author

/run-all-tests

@github-actions github-actions bot added the sig/sql-infra SIG: SQL Infra label Feb 22, 2021
@cfzjywxk cfzjywxk added the require-LGT3 Indicates that the PR requires three LGTM. label Feb 23, 2021
@@ -2257,6 +2250,7 @@ func (s *session) InitTxnWithStartTS(startTS uint64) error {
if err != nil {
return err
}
s.initTxn()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this bring some side effects?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL @tiancaiamao , thx!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To lower the risk, changes to NewTxn and initTxnWithStartTS are removed.

@cfzjywxk
Copy link
Contributor Author

Or shold we just change it back to use PrepareTxnCtx before retry instead of NewTxn.
For the panic issue #21284, we just add a validation check for txn and use it if it's valid at L593, to solve the panic issue.
This will reduce the change size lower the change risk.

@coocood @lysu @youjiali1995 @wjhuang2016 @jackysp

@youjiali1995
Copy link
Contributor

Or shold we just change it back to use PrepareTxnCtx before retry instead of NewTxn.
For the panic issue #21284, we just add a validation check for txn and use it if it's valid at L593, to solve the panic issue.
This will reduce the change size lower the change risk.

@coocood @lysu @youjiali1995 @wjhuang2016 @jackysp

Agree with it. We can merge changes of this PR to master.

@coocood
Copy link
Member

coocood commented Feb 23, 2021

Or shold we just change it back to use PrepareTxnCtx before retry instead of NewTxn.
For the panic issue #21284, we just add a validation check for txn and use it if it's valid at L593, to solve the panic issue.
This will reduce the change size lower the change risk.

@coocood @lysu @youjiali1995 @wjhuang2016 @jackysp

+1

@jackysp
Copy link
Member

jackysp commented Feb 23, 2021

Or shold we just change it back to use PrepareTxnCtx before retry instead of NewTxn.
For the panic issue #21284, we just add a validation check for txn and use it if it's valid at L593, to solve the panic issue.
This will reduce the change size lower the change risk.

@coocood @lysu @youjiali1995 @wjhuang2016 @jackysp

The set statement should be retried in the same transaction with other history statements. If it is the first statement of the history and the session only prepared a transaction but didn't active it, the set statement may make the retry results not as expected. e.g.

set autocommit = 0;
select * from t;
set @a=@@tidb_current_ts;
update t set startts = @a where xxx;
commit;

If the above transaction retried, the column startts will be set to 0, because some variables are transaction related.

@cfzjywxk cfzjywxk force-pushed the fix_retry_with_non_autocommit branch from ef78bfc to d4cbe9d Compare February 23, 2021 07:34
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 23, 2021
@cfzjywxk
Copy link
Contributor Author

/run-all-tests

@coocood
Copy link
Member

coocood commented Feb 23, 2021

LGTM

@ti-chi-bot
Copy link
Member

@coocood: Please use /LGTM instead of LGTM when you want to approve the pull request by comment.
If you use the GitHub review feature, please approve the PR directly, the comment will not take effect in the GitHub review feature.
If you have any qustions please refer to lgtm command help or lgtm plugin design.

If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@coocood
Copy link
Member

coocood commented Feb 23, 2021

/LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 23, 2021
session/session.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot
Copy link
Member

@AilinKid: Please use /LGTM instead of LGTM when you want to approve the pull request by comment.
If you use the GitHub review feature, please approve the PR directly, the comment will not take effect in the GitHub review feature.
If you have any qustions please refer to lgtm command help or lgtm plugin design.

If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@AilinKid
Copy link
Contributor

/LGTM

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 23, 2021
@cfzjywxk
Copy link
Contributor Author

/run-all-tests

session/session.go Outdated Show resolved Hide resolved
Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot
Copy link
Member

@jackysp: Please use /LGTM instead of LGTM when you want to approve the pull request by comment.
If you use the GitHub review feature, please approve the PR directly, the comment will not take effect in the GitHub review feature.
If you have any qustions please refer to lgtm command help or lgtm plugin design.

If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Copy link
Contributor

@youjiali1995 youjiali1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@cfzjywxk
Copy link
Contributor Author

/run-all-tests

@youjiali1995
Copy link
Contributor

/LGTM

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • AilinKid
  • coocood
  • youjiali1995

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Feb 23, 2021
@jackysp
Copy link
Member

jackysp commented Feb 23, 2021

/LGTM

@jebter
Copy link

jebter commented Feb 23, 2021

/label cherry-pick-approved

@jebter jebter added the cherry-pick-approved Cherry pick PR approved by release team. label Feb 23, 2021
@jebter
Copy link

jebter commented Feb 24, 2021

/merge

@ti-chi-bot
Copy link
Member

@jebter: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 8f8d450

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 24, 2021
@ti-chi-bot ti-chi-bot merged commit 8e68350 into pingcap:release-4.0 Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. priority/release-blocker This issue blocks a release. Please solve it ASAP. require-LGT3 Indicates that the PR requires three LGTM. sig/sql-infra SIG: SQL Infra sig/transaction SIG:Transaction size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants